package sd.qd.xiaoming.coffeedesk.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * 存储文件的目录
 */
@Entity
@XmlRootElement
public class CdDirectory extends BaseEntity {

	private String name;
	private Date editTime;
	private CdDirectory parent;
	private List<CdDirectory> children = new ArrayList<CdDirectory>();
	private List<CdFile> files = new ArrayList<CdFile>();

	@OneToMany(fetch = FetchType.LAZY, targetEntity = CdDirectory.class, mappedBy = "parent", cascade = { CascadeType.ALL })
	public List<CdDirectory> getChildren() {
		return this.children;
	}

	public Date getEditTime() {
		return this.editTime;
	}

	@OneToMany(targetEntity = CdFile.class, mappedBy = "directory", cascade = { CascadeType.ALL })
	public List<CdFile> getFiles() {
		return this.files;
	}

	public String getName() {
		return this.name;
	}

	@ManyToOne
	public CdDirectory getParent() {
		return this.parent;
	}

	public void setChildren(final List<CdDirectory> children) {
		this.children = children;
	}

	public void setEditTime(final Date editTime) {
		this.editTime = editTime;
	}

	public void setFiles(final List<CdFile> files) {
		this.files = files;
	}

	public void setName(final String name) {
		this.name = name;
	}

	public void setParent(final CdDirectory parent) {
		this.parent = parent;
	}

	@Override
	public String toString() {
		return "CdDirectory [name=" + this.name + ", editTime=" + this.editTime + ", parent=" + this.parent + ", children=" + this.children + ", files=" + this.files + "]";
	}



}
